---@class view
---@field renderer view.renderer
local view = {}
view.__index = view

---@class view.renderer
local renderer = {}
renderer.__index = renderer

view.renderer = renderer

---comment
---@return view
function view:new_view_type()
    local new_view_type  = {}
    setmetatable(new_view_type, new_view_type)
    new_view_type.__index = self

    return new_view_type
end

---@param other view
function view:is_same_view_type(other)
    return other.__index == self.__index
end

---Create a new view renderer subclass
---@return view.renderer - view.renderer subclass
function renderer:new_renderer_type()
    local new_renderer_type = {}
    setmetatable(new_renderer_type, new_renderer_type)
    new_renderer_type.__index = self

    return new_renderer_type
end

---@return view
function view:set_view_prototype(view_instance)
    setmetatable(view_instance, view_instance)
    view_instance.__index = self
    return view_instance
end

---@return view.renderer
function view:set_renderer_prototype(renderer_instance)
    setmetatable(renderer_instance, renderer_instance)
    renderer_instance.__index = self.renderer

    return renderer_instance
end

---Override this method to create new renderer instance
---@return view.renderer
function view:create_renderer_instance()
    error("view:create_renderer_instance() is not implemented")
end

---Layout a view by constraints
---@param constraints constraints
---@param view view
---@return constrained_size
function renderer:layout(constraints, view)
    error("renderer:layout(constraints, view) is not implemented")
end

---Render a view
---@param render_rect rect
---@param view view
function renderer:render(render_rect, view)
    error("renderer:render(render_rect, view) is not implemented")
end

---Override this function if you need the destroy behaviour
function renderer:destroy()
end

return view
